<template>
  <div class="page-search">
    <zh-form v-bind="searchConfig" v-model="formData">
      <template #header>
        <h1>高级检索</h1>
      </template>
      <template #footer>
        <div class="Fbtns">
          <el-button icon="CircleClose" @click="handleResetClick"
            >重置</el-button
          >
          <el-button type="primary" icon="Search" @click="handleQueryClick"
            >搜索</el-button
          >
        </div>
      </template>
    </zh-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import zhForm from '@/base-ui/form'
export default defineComponent({
  name: 'pageSearch',
  components: {
    zhForm
  },
  props: {
    searchConfig: {
      type: Object,
      required: true
    }
  },
  emits: ['resetBtnClick', 'queryBtnClick'],
  setup(props, { emit }) {
    const formItems = props.searchConfig.formItems ?? []
    const formOriginData: any = {}
    for (const item of formItems) {
      formOriginData[item.field] = ''
    }
    const formData = ref(formOriginData)
    const handleResetClick = () => {
      // formData.value = formOriginData
      for (const key in formOriginData) {
        formData.value[`${key}`] = formOriginData[key]
        emit('resetBtnClick')
      }
    }
    //点击搜索
    const handleQueryClick = () => {
      emit('queryBtnClick', formData.value)
    }
    return {
      formData,
      handleResetClick,
      handleQueryClick
    }
  }
})
</script>

<style scoped>
.Fbtns {
  text-align: right;
  padding: 0px 20px 10px 20px;
}
</style>
